import request from '@/utils/request'

/**
 * 获取商品列表数据
 *
 * @param {*} params
 * @returns
 */
export const getGoodsList = params => {
  return request({
    url: '/goods?pagenum=' + params.pagenum + '&pagesize=' + params.pagesize + '&query=' + params.query,
    method: 'get'
  })
}

/**
 * 添加商品
 *
 * @param {*} params
 * @returns
 */
export const postAddGoods = params => {
  return request({
    url: '/goods',
    method: 'post',
    data: params
  })
}

/**
 * 根据 ID 查询商品信息
 *
 * @param {*} params
 * @returns
 */
export const getGoodsInfoById = params => {
  return request({
    url: `/goods/${params}`,
    method: 'get'
  })
}

/**
 * 编辑商品信息提交
 *
 * @param {*} params
 * @returns
 */
export const putEditGoodsInfo = params => {
  return request({
    url: `/goods/${params.goods_id}`,
    method: 'put',
    data: params
  })
}

/**
 * 删除商品
 *
 * @param {*} params
 * @returns
 */
export const delGoodsById = params => {
  return request({
    url: `/goods/${params}`,
    method: 'delete'
  })
}

/**
 * 获取商品分类数据列表
 *
 *  @returns
 */
export const getCate = () => {
  return request({
    url: '/categories',
    method: 'get'
  })
}

/**
 * 获取参数分类列表
 *
 * @param {sel: many / only} params
 * @returns
 */
export const getCateById = params => {
  return request({
    url: `/categories/${params.id}/attributes`,
    method: 'get',
    params: {
      sel: params.sel
    }
  })
}

/**
 * 根据 ID 查询参数

 * @param {attr_sel: many / only} params
 * @returns
 */
export const getCateAttrById = params => {
  return request({
    url: `/categories/${params.id}/attributes/${params.attrId}`,
    method: 'get',
    params: {
      attr_sel: params.attr_sel
    }
  })
}

/**
 * 删除参数
 *
 * @param {*} params
 * @returns
 */
export const delCateAttrById = params => {
  return request({
    url: `/categories/${params.id}/attributes/${params.attrId}`,
    method: 'delete'
  })
}

/**
 * 添加动态参数或者静态属性
 *
 * @param {attr_sel: many / only} params
 * @returns
 */
export const postCateById = params => {
  return request({
    url: `/categories/${params.id}/attributes`,
    method: 'post',
    data: {
      attr_name: params.attr_name,
      attr_sel: params.attr_sel
    }
  })
}

/**
 * 编辑提交参数
 *
 * @param {attr_sel: many / only} params
 * @returns
 */
export const putCateAttrById = params => {
  return request({
    url: `/categories/${params.id}/attributes/${params.attrId}`,
    method: 'put',
    data: {
      attr_name: params.attr_name,
      attr_sel: params.attr_sel,
      attr_vals: params.attr_vals
    }
  })
}

/**
 * 商品分类数据列表
 *
 * @param {type: 1, 2, 3} params 一层, 二层, 三层分类列表
 * @returns
 */
export const getCateByType = params => {
  return request({
    url: '/categories?type=' + params.type + '&pagenum=' + params.pagenum + '&pagesize=' + params.pagesize,
    method: 'get'
  })
}

/**
 * 添加分类
 *
 * @param {*} params
 * @returns
 */
export const postCate = params => {
  return request({
    url: '/categories',
    method: 'post',
    data: params
  })
}

/**
 * 根据 ID 查询分类参数

 * @param {*} params
 * @returns
 */
export const getCategoriesById = params => {
  return request({
    url: `/categories/${params}`,
    method: 'get'
  })
}

/**
 * 编辑提交
 *
 * @param {*} params
 * @returns
 */
export const putCategoriesById = params => {
  return request({
    url: `/categories/${params.cat_id}`,
    method: 'put',
    data: {
      cat_name: params.cat_name
    }
  })
}

/**
 * 删除分类
 *
 * @param {*} params
 * @returns
 */
export const delCategoriesById = params => {
  return request({
    url: `/categories/${params}`,
    method: 'delete'
  })
}
